#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

struct ListNode 
{
    int val;
    struct ListNode* next;
};

struct ListNode* rotateRight(struct ListNode* head, int k)
{
    if (k == 0 || head == NULL || head->next == NULL)
    {
        return head;
    }
    struct ListNode* cur = head;
    int i = 1;
    while (cur->next != NULL)
    {
        cur = cur->next;
        i++;
    }
    int mid = i - k % i;
    if (mid == i)
        return head;
    cur->next = head;
    while (mid--)
    {
        cur = cur->next;
    }
    struct ListNode* newhead = cur->next;
    cur->next = NULL;
    return newhead;
}